import 'package:flutter/material.dart';

class DetailPage extends StatelessWidget {
  int counter;

  DetailPage({Key? key, required this.counter}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("详情页面"),
        leading: IconButton(
          icon: Icon(Icons.arrow_back),
          onPressed: () => back(context),
        ),
      ),
      body: Center(
        child: TextButton(
            onPressed: () => back(context),
            child: Text(
              "点击返回  当前计数：$counter",
              style: TextStyle(fontSize: 20, color: Colors.black),
            )),
      ),
    );
  }

  void back(BuildContext context) {
    Navigator.of(context).pop(counter + 1);
  }
}
